package com.huang.lock8;

import java.util.concurrent.TimeUnit;

public class test2 {
    public static void main(String[] args) {

        Phone2 phone=new Phone2();
        new Thread(()->{
        phone.sendSms();
        },"Sms").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            phone.hello();
        },"email").start();
    }

}

//锁的是  对象的调用者 phone  唯一 谁拿到谁执行
class Phone2{
    public synchronized void sendSms(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Sms");
    }
    public synchronized void sendEmail(){
        System.out.println("EMAIL");
    }


    //没有锁  不受锁的影响
    public void hello(){
        System.out.println("hello");
    }

}
